﻿// Shader-Based-Image-Processing (SBIP)
// http://code.google.com/p/sbip/
//
// Copyright © Frank Nagl, 2009-2010
// admin@franknagl.de
//
namespace SBIP.Filter
{
    using Microsoft.Xna.Framework.Graphics;

    /// <summary>
    /// Chessboard image.
    /// </summary>
    /// <remarks>
    /// <para>No image filtering. Just creating a chessboard texture or image :-).</para>
    /// 
    /// <para>Sample usage:</para>
    /// <code>
    ///  // 1. Offline rendering
    ///  // create Processor, used as rendering framework
    ///  Processor processor = new Processor();
    ///  // starts Processor
    ///  processor.Begin( image );
    ///  // create Chessboard filter
    ///  Chessboard filter = new Chessboard( );
    ///  // optional: configure filter
    ///  filter.SquaresPerSide = 10.0f;
    ///  processor.Filter = filter;
    ///  // apply the filter  
    ///  Bitmap resultImage = processor.RenderToBitmap( );
    ///  Texture2D resultTexture = processor.RenderToTexture( );
    ///  processor.End( );
    ///  
    ///  // 2. Online rendering
    ///  // create any windows control for rendering in
    ///  Form myForm = new Form( );
    ///  // create Processor, used as rendering framework
    ///  Processor processor2 = new Processor( );
    ///  // starts Processor
    ///  processor2.Begin( image, myForm );
    ///  // create Chessboard filter
    ///  Chessboard filter2 = new Chessboard( );
    ///  // optional: configure filter
    ///  filter2.SquaresPerSide = 10.0f;
    ///  processor2.Filter = filter;
    ///  // apply the filter
    ///  myForm.Show( );
    ///  while ( myForm.Created )
    ///  {
    ///      processor2.Render( );
    ///      Application.DoEvents( );
    ///  }
    ///  processor2.End( );
    /// </code>
    /// 
    /// <para><b>Initial image:</b></para>
    /// <img src="img/shaderbased/sample1.jpg" width="480" height="361" />
    /// <para><b>Result image:</b></para>
    /// <img src="img/shaderbased/Chessboard.jpg" width="480" height="361" />
    /// </remarks>
    public sealed class Chessboard : BaseFilter
    {
        private float squaresPerSide;
        /// <summary>
        /// The number of squares per side of the chessboard.
        /// </summary>
        /// <remarks>Default value: 8.0</remarks>
        public float SquaresPerSide
        {
            get { return squaresPerSide; }
            set
            {
                if (Effect == null)
                    throw new System.ArgumentException("SquaresPerSide" + InitMsg);

                squaresPerSide = value;
                Effect.Parameters["SquaresPerSide"].SetValue(SquaresPerSide);
            }
        } 

        /// <summary>
        /// Initializes a new instance of the <see cref="Chessboard"/> class.
        /// </summary>
        public Chessboard() : base("Chessboard") { }

        /// <summary>
        /// Sets the start value of property <see cref="SquaresPerSide"/>.
        /// </summary>
        protected override void PostInit()
        {
            SquaresPerSide = 8.0f;
        }
    }
}
